package com.joysuch.wwyt.bp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joysuch.wwyt.bp.bean.investigate.BpInvestigateTaskQueryBean;
import com.joysuch.wwyt.bp.bean.investigate.vo.BpInvestigateTaskHisVO;
import com.joysuch.wwyt.bp.entity.BpInvestigateTaskHis;
import com.joysuch.wwyt.bp.entity.BpInvestigateTaskSummary;
import com.joysuch.wwyt.bp.entity.BpInvestigateTaskSummaryHis;
import com.joysuch.wwyt.bp.entity.dto.UserTaskRecordDto;
import com.joysuch.wwyt.bp.entity.investigate.BpInvestigateRecord;
import com.joysuch.wwyt.bp.entity.investigate.BpInvestigateRecordItem;
import com.joysuch.wwyt.bp.entity.investigate.BpInvestigateTask;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author heqifeng
 * @since 2022-06-08
 */
@Repository
public interface BpInvestigateTaskHisMapper extends BaseMapper<BpInvestigateTaskHis> {

    BpInvestigateTask getHistoryTaskById(@Param("taskId") Long taskId);

    boolean deleteTaskById(@Param("taskId") Long taskId);

    boolean deleteRecordHistoryById(@Param("recordId") Long recordId);

    boolean deleteRecordItemHistoryByRecordId(@Param("recordId") Long recordId);

    boolean deleteSummaryHistoryById(@Param("id") Long id);

    boolean deleteSummaryByTaskId(@Param("taskId") Long taskid, @Param("isHistory") boolean isHistory);

    /**
     * 重置summary上的相关计数，并删除
     */
    boolean resetSummaryCountByTaskId(@Param("taskId") Long taskId,@Param("isHistory") boolean isHistory);

    BpInvestigateRecordItem getHistoryItemById(@Param("itemId") Long itemId);

    List<BpInvestigateRecordItem> getHistoryItemByRecordId(@Param("recordId") Long recordId);

    boolean updateRecordItemRepairStatus(@Param("id") Long id,@Param("repairStatus") String repairStatus);

    boolean updateRecordItemRepairStatusAndWfStatus(@Param("id") Long id, @Param("repairStatus") String repairStatus,
                                                    @Param("wfProcessInsId") String wfProcessInsId,@Param("wfProcessStatus") String wfProcessStatus);

    void updateRepairStatusByTaskId(@Param("status") String status, @Param("taskId") Long taskId);

    BpInvestigateRecord getRecordById(@Param("id") Long id);

    List<BpInvestigateRecord> getRecordByTaskIds(@Param("taskIds") Collection<Long> taskIds);

    BpInvestigateRecord getRecordByTaskId(@Param("taskId") Long taskId,@Param("isHistory") boolean isHistory);

    List<Long> getAssignUserByTaskId(@Param("taskId") Long taskId, @Param("isHistory") boolean isHistory);

    boolean updateSummaryCountByUserAndDate(@Param("userIds") Collection<Long> userIds, @Param("date") Date date, @Param("checkResult") String checkResult, @Param("isHistory") boolean isHistory);

    List<Long> getUserIdsByTaskId(Long id);

    BpInvestigateTaskSummary getByDateAndUserId(Date startTime, Date endTime, Long userId);

    List<String> findExceptionProcessResult(Date startTime, Date endTime, Long assign, Long itemId);

    int updateExceptionProcessResultBatchById(String exceptionProcessResult, List<Long> ids);

    BpInvestigateRecord findRecordByItemId(@Param("itemId") Long itemId);

    boolean updateRecordItemRef(@Param("recordItem") BpInvestigateRecordItem recordItem);

    List<BpInvestigateTaskSummaryHis> getSummaryByTaskId(@Param("taskId") Long taskId, @Param("date") Date date,@Param("isHistory") boolean isHistory);

    List<UserTaskRecordDto> findRepairStatusByDate(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("userIds") List<Long> userIds,@Param("isHistory") boolean isHistory);

    /**
     * 分页查询检查记录-历史
     *
     * @param page
     * @param queryBean
     * @return
     */
    Page<BpInvestigateTaskHisVO> pageBpInvestigateTaskHis(Page<BpInvestigateTaskHisVO> page, @Param("queryBean") BpInvestigateTaskQueryBean queryBean, @Param("userIds") List<Long> userIds);

    List<BpInvestigateTaskHis> getFinishOldSourceTask(@Param("lastTaskId") Long lastTaskId);

    long copyHisTaskToYearTaskByIds(@Param("taskIds") List<Long> taskIds, @Param("year") String year);

    void deleteTaskByIds(@Param("taskIds") List<Long> taskIds);

    List<Long> getHisRecordIdByHisTaskIds(@Param("taskIds") List<Long> taskIds);

    void deleteHisTaskByIds(@Param("taskIds") List<Long> taskIds);

    List<BpInvestigateTaskHis> getMoveTaskIds(@Param("endDate") Date endDate, @Param("type") int type);

}
